/* eslint-disable no-undef */

function jxrandom (min, max) {
  return Math.random() * (max - min) + min
}
function jxrandomint (min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min
}
function jxrandomarr (arr) {
  return arr[Math.floor(Math.random() * arr.length)]
}
// 对象随机key
function jxrandomkey (obj) {
  var arr = Object.getOwnPropertyNames(obj)
  return arr[Math.floor(Math.random() * arr.length)]
}
// 对象随机value
function jxrandomvalue (obj) {
  var arr = Object.getOwnPropertyNames(obj)
  return obj[arr[Math.floor(Math.random() * arr.length)]]
}

// 获取组件
function jxdom (text) {
  return document.getElementById(text)
}

function jxcbutton (id, text, value, eclass) {
  var obj = document.createElement('button')
  obj.innerHTML = text
  obj.setAttribute('type', 'button')
  obj.setAttribute('class', eclass)
  obj.setAttribute('value', value)
  obj.setAttribute('id', id)
  return obj
}
function jxctext (text) {
  var obj = document.createElement('div')
  obj.innerHTML = text
  obj.setAttribute('type', 'text')
  return obj
}
function jxcspan (text) {
  var obj = document.createElement('span')
  obj.innerHTML = text
  return obj
}
function jxcvue (name) {
  var obj = document.createElement(name)
  return obj
}

function jxtoast (msg) {
  this.$toast(msg)
}

function jxpop (body, title) {
  this.$alert(body, title, {
    confirmButtonText: '确定',
    showClose: false,
    center: true
  })
}

export default {
  jxrandom,
  jxrandomint,
  jxrandomarr,
  jxrandomkey,
  jxrandomvalue,

  jxdom,
  jxcbutton,
  jxctext,
  jxcspan,
  jxcvue,

  jxtoast,
  jxpop
}
